<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="标题">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="作者" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.auther }}</span>
        </template>
      </el-table-column>
      <el-table-column label="浏览量" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.pageviews }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="发布时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"/>
          <span>{{ scope.row.update_time }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="operation" label="操作 " width="200">
        <template slot-scope="scope" >
         <el-button size="small" type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
         <!-- <el-button v-if="scope.row.status!='2'" size="mini" type="success" @click="handleModifyStatus(scope.row,'2')">启用
          </el-button>
          <el-button v-if="scope.row.status!='1'" size="mini" @click="handleModifyStatus(scope.row,'1')">禁用
          </el-button> -->
          <el-button size="small" type="danger" @click="showDialog(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="500"
      style="width:500px;margin:0 auto;margin-top:40px;">
    </el-pagination>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%">
      <span>你确定要删除这条新闻吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="hanleDele(rowobj)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from '@/api/article'
import constantRouterMap from '@/router/index'
export default {
  data() {
    return {
      list: null,
      listLoading: true,
      pages: 5,
      dialogVisible: false,
      rowobj: ''
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      // alert(this.listQuery)
      getList(this.listQuery).then(response => {
        // this.pages = response.data.totalpages
        // console.log(response.data)
        this.list = response.data.list
        this.listLoading = false
      })
    },
    showDialog(row) {
      this.dialogVisible = true
      this.rowobj = row
    },
    handleUpdate(row) {
      constantRouterMap.push({ name: 'quillEditor', params: { row: row }})
    },
    hanleDele(rowobj) {
      this.list.splice(rowobj.index, 1)
      this.dialogVisible = false
    }
  }
}
</script>
